<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2018/9/6
 * Time: 12:37
 */

namespace app\student\model;

use app\common\model\Mysql;

class StudentManager extends Mysql{

    const DB_NAME = 'student';

    public function isStudentExist($id,$name){
        return $this->getStudentByCustom(array("id"=>$id,"name"=>$name));
    }

    public function  getStudentById(){

    }

    public function insertStudent($examinfo){
        return $this->insertSQLbyCustom(self::DB_NAME,$examinfo);
    }

    public function getStudentAllByClass($class){
        return $this->getStudentAllByCustom(array("class"=>$class));
    }

    protected function getStudentAllByCustom($customKey=[]){
        return $this->selectSQLAllbyCustom(self::DB_NAME,$customKey);
    }

    protected function getStudentByCustom($customKey=[]){
        if(count($customKey) == 0){
            $studentSql = "select * from " .self::DB_NAME;
        }else{
            $condition = null;
            foreach ($customKey as $key=>$value){
                //echo "Key: $key; Value: $value<br />\n";
                if($condition==null){
                    $condition = $condition." $key='$value'";
                }else{
                    $condition = $condition." and $key='$value'";
                }

            }

            $studentSql = "select * from " .self::DB_NAME. " where " .$condition;
        }

        $data = $this->selectSQL($studentSql);

        return $data;
    }
}